<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var appOrderManageDataGrid;
    $(function() {
        appOrderManageDataGrid = $('#appOrderManageDataGrid').datagrid({
            url : '${path }/appOrderManage/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                title : 'id',
                field : 'id',
                width : 40,

                hidden : true
            } ] ],
            columns : [ [ {
                field : 'orderCode',
                title : '订单编码',
                width : 150
            },{
                field : 'goodsCode',
                title : '商品编码',
                width : 80
            },{
                field : 'goodsName',
                title : '商品名称 ',
                width : 100
            },{
                field : 'goodsPrice',
                title : '商品单价',
                width : 60
            },{
                field : 'goodsNum',
                title : '商品数量',
                width : 60
            },{
                field : 'goodsTprice',
                title : '商品总价',
                width : 70
            },{
                field : 'receName',
                title : '收货人姓名',
                width : 100
            },{
                field : 'receTel',
                title : '收货人电话',
                width : 100
            },{
                field : 'receAddress',
                title : '收货人地址',
                width : 200
            },{
                field : 'createTime',
                title : '创建时间',
                width : 130
            },{
                field: 'orderStatus',
                title: '状态',
                width: '80',
                sortable:true,
                formatter : function(value, row, index){
                    switch (value){
                        case 0:
                            return '正常';
                        case 1:
                            return '已收货 ';
                        case 2:
                            return '退货';
                        case 3:
                            return '换货';
                        case 4:
                            return '取消';
                        case 5:
                            return '发货';
                    }
                }
            },{
                width : 130,
                title : '创建时间',
                field : 'createTime'
            },{
                field : 'action',
                title : '操作',
                width : 130,
                formatter : function(value, row, index) {
                    var str = '';
                    if(row.orderStatus == 0){
                        <shiro:hasPermission name="/appOrderManage/edit">
                            str += $.formatString('<a href="javascript:void(0)" class="appOrderManage-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editAppOrderManageFun(\'{0}\');" >编辑</a>', row.id);
                        </shiro:hasPermission>
                        <shiro:hasPermission name="/appOrderManage/delete">
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="appOrderManage-easyui-linkbutton-deliverGoods" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deliverGoodsFun(\'{0}\');" >发货</a>', row.id);
                        </shiro:hasPermission>
                    }else{
                        str += $.formatString('<a href="javascript:void(0)" class="appOrderManage-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" >编辑</a>' );
                        str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                        str += $.formatString('<a href="javascript:void(0)" class="appOrderManage-easyui-linkbutton-deliverGoods" data-options="plain:true,iconCls:\'fi-x icon-red\'"   >发货</a>', row.id);
                    }
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.appOrderManage-easyui-linkbutton-deliverGoods').linkbutton({text:'发货'});
                $('.appOrderManage-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            }
        });
    });



    function editAppOrderManageFun(id) {
        if (id == undefined) {
            var rows = appOrderManageDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            appOrderManageDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 700,
            height : 400,
            href : '${path }/appOrderManage/editPage?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = appOrderManageDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#appOrderManageEditForm');
                    f.submit();
                }
            } ]
        });
    }

    /**
     *  发货管理
     * */
    function  deliverGoodsFun(id) {
        if (id == undefined) {
            var rows = appOrderManageDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            appOrderManageDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '发货',
            width : 700,
            height : 400,
            href : '${path }/appOrderManage/editDeliverGoodsPage?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = appOrderManageDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#appOrderDeliverGoodsEditForm');
                    f.submit();
                }
            } ]
        });
    }



</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',fit:true,border:false">
        <table id="appOrderManageDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
